﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;

namespace DBService
{
	public partial class DlgProjectView : System.Windows.Forms.Form
	{
		public DlgProjectView(DbProject project)
		{
			this.mProject = project;
			this.InitializeComponent();
		}

		private void initTrElement()
		{
			this.tvElement.Nodes["删除构件"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["梁"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["剪力墙"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["柱"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["板"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["开洞"].Nodes.Clear();
			this.tvElement.Nodes["修改构件"].Nodes["电缆沟"].Nodes.Clear();
		}

		private void DlgProjectView_Load(object sender, EventArgs e)
		{
			this.initTrElement();
			foreach (DbElementForRemove dbElementForRemove in this.mProject.ElementForRemove())
			{
				TreeNode treeNode = new TreeNode(dbElementForRemove.ToString());
				treeNode.Tag = dbElementForRemove;
				this.tvElement.Nodes["删除构件"].Nodes.Add(treeNode);
			}
			foreach (DbBeam dbBeam in this.mProject.BeamToModify())
			{
				TreeNode treeNode2 = new TreeNode(dbBeam.ToString());
				treeNode2.Tag = dbBeam;
				this.tvElement.Nodes["修改构件"].Nodes["梁"].Nodes.Add(treeNode2);
			}
			foreach (DbColumn dbColumn in this.mProject.ColumnToModify())
			{
				TreeNode treeNode3 = new TreeNode(dbColumn.ToString());
				treeNode3.Tag = dbColumn;
				this.tvElement.Nodes["修改构件"].Nodes["柱"].Nodes.Add(treeNode3);
			}
			foreach (DbSlab dbSlab in this.mProject.SlabToModify())
			{
				TreeNode treeNode4 = new TreeNode(dbSlab.ToString());
				treeNode4.Tag = dbSlab;
				this.tvElement.Nodes["修改构件"].Nodes["板"].Nodes.Add(treeNode4);
			}
			foreach (DbOpening dbOpening in this.mProject.OpeningToModify())
			{
				TreeNode treeNode5 = new TreeNode(dbOpening.ToString());
				treeNode5.Tag = dbOpening;
				this.tvElement.Nodes["修改构件"].Nodes["开洞"].Nodes.Add(treeNode5);
			}
			foreach (DbDitch dbDitch in this.mProject.DitchToModify())
			{
				TreeNode treeNode6 = new TreeNode(dbDitch.ToString());
				treeNode6.Tag = dbDitch;
				this.tvElement.Nodes["修改构件"].Nodes["电缆沟"].Nodes.Add(treeNode6);
			}
			foreach (DbWall dbWall in this.mProject.WallToModify())
			{
				TreeNode treeNode7 = new TreeNode(dbWall.ToString());
				treeNode7.Tag = dbWall;
				this.tvElement.Nodes["修改构件"].Nodes["剪力墙"].Nodes.Add(treeNode7);
			}
		}

		private void tvElement_AfterSelect(object sender, TreeViewEventArgs e)
		{
			this.propertyGrid2.SelectedObject = null;
			if (this.tvElement.SelectedNode != null)
			{
				if (this.tvElement.SelectedNode.Tag is DbBeam)
				{
					this.propertyGrid2.SelectedObject = (DbBeam)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbColumn)
				{
					this.propertyGrid2.SelectedObject = (DbColumn)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbDitch)
				{
					this.propertyGrid2.SelectedObject = (DbDitch)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbSlab)
				{
					this.propertyGrid2.SelectedObject = (DbSlab)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbOpening)
				{
					this.propertyGrid2.SelectedObject = (DbOpening)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbElementForRemove)
				{
					this.propertyGrid2.SelectedObject = (DbElementForRemove)this.tvElement.SelectedNode.Tag;
					return;
				}
				if (this.tvElement.SelectedNode.Tag is DbWall)
				{
					this.propertyGrid2.SelectedObject = (DbWall)this.tvElement.SelectedNode.Tag;
				}
			}
		}

		private DbProject mProject;
	}
}
